<%@ page language="java" contentType="text/html; charset=UTF-8;" pageEncoding="UTF-8" %>
<%@ taglib uri="/WEB-INF/taglib/emc.tld" prefix="emc"%>
<%@ taglib uri="/WEB-INF/taglib/emc-spring.tld" prefix="emc-spring"%>
<%@ taglib uri="/WEB-INF/taglib/spring-form.tld" prefix="spring-form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<emc:basePath/>
<script src="js/jquery-1.10.1.min.js"></script>
<style type="text/css">
div {
	margin-left: auto;
	margin-right: auto;
	text-align: center;
	border: 1px solid ;
	width: 35%;
}
label {
	float: left;
	width: 23px;
	margin-right: 10px;
	text-align: right;
	font-weight: bold;
	clear: left;
}
.title {
	font-size:20px;
	color: red;
}
.error {
	color: red;
	text-align: right;
}
</style>
<script>
	$(document).ready(function() {

		$("#addUser").click(function(event) {
			$.ajax({
				type : "post",
				contentType : "application/json",
				url : "addUser.cl",
				data : JSON.stringify({
					id : 1,
					username : "Joly",
					age : 3,
					birthday : "2010-01-01"
				}),
				dataType : 'json',
				success : function(result) {
					if (result._exceptionMessage) {
						alert(result._exceptionLocalizedMessage);
					}
					;
					if (result._fieldErrors) {
						alert(result._fieldErrors.name);
					}
				}
			});
		});

	});
</script>

<title>User</title>
</head>
<body>
	<div>
		<spring-form:form commandName="user" action="addUser.do" method="post">
			<p>
				<span class="title">application/x-www-form-urlencoded</span>
			</p>
			<p>
				<emc:error />
			</p>
			<p>
				<label>id:</label>
				<input name="id" value="${param.id }" value="1" />
				<span class="error"><spring-form:errors path="id" /></span>
			</p>
			<p>
				<label>username:</label>
				<input name="username" value="${param.username }" value="Joly" />
				<span class="error"><spring-form:errors path="username"  /></span>
			</p>
			<p>
				<label>password:</label>
				<input name="password" value="${param.password }" value="123456" />
				<span class="error"><spring-form:errors path="password"  /></span>
			</p>
			<p>
				<label>cifId:</label>
				<input name="cif.id" value="${param.cif.id }" value="1" />
				<span class="error"><spring-form:errors path="cif.id" /></span>
			</p>
			<p>
				<label>cifUsername:</label>
				<input name="cif.cifName" value="${param.cif.cifName }" value="Joly_Huang" />
				<span class="error"><spring-form:errors path="cif.cifName"  /></span>
			</p>
			<p>
				<label>cifAge:</label>
				<input name="cif.age" value="${param.cif.age }" value="12" />
				<span class="error"><spring-form:errors path="cif.age" /></span>
			</p>
			<p>
				<label>cifBirthday:</label>
				<input name="cif.birthday" value="${param.cif.birthday }" value="2010-01-01" />
				<span class="error"><spring-form:errors path="cif.birthday" /></span>
			</p>
			<emc:backReferer referer="initAddUser.do" />
			<emc-spring:token/>
			<input type="submit" value="添加" />
		</spring-form:form>
	</div>
	
	<div>
		<p>
			<span class="title">application/json</span>
		</p>
		<form id="addUserForm" action="user.html" method="post">
			<p>
				<label>id:</label>
				<input name="id" value="1" />
				<span class="error"><spring-form:errors path="id" /></span>
			</p>
			<p>
				<label>name:</label>
				<input name="username" value="Joly" />
				<span class="error"><spring-form:errors path="username" /></span>
			</p>
			<p>
				<label>age:</label>
				<input name="age" value="3" />
				<span class="error"><spring-form:errors path="age" /></span>
			</p>
			<p>
				<label>birthday:</label>
				<input name="birthday" value="2010-01-01" />
				<span class="error"><spring-form:errors path="birthday" /></span>
			</p>
			<input id="addUser" type="button" value="json添加" />
		</form>
	</div>
</body>
</html>